<?php 

function contest_format_date($input) {
    if(!$input) {
        return "";
    }
    $d = substr($input, 0, 16);    
    $d = str_replace("-",".", $d);
    
    $darrs = explode(" ", $d);
    $date = $darrs[0];
    $time = $darrs[1];
    $dateArrs = explode(".", $date);
    $dateStr = $dateArrs[2] . "." . $dateArrs[1] . "." . $dateArrs[0];
    return $dateStr . " " . $time;
}

?>
<script type="text/javascript" >
    jQuery(document).ready(function() {
        stContestToolbox.load_tooltip();
        stContestToolbox.on_submitform('#stFacebookToolboxForm');
        stContestToolbox.loadUploadButton();
        stContestToolbox.loadRemoveButton();
        stContestToolbox.showSideMenu('<?php echo $current_action; ?>');  
    });
</script>
<style type="text/css">
    legend.contest_legend{
        font-size: 14px;
        font-weight: bolder;
        padding: 3px;
    }
    .wp-media-buttons a {
        position: absolute;
        margin-top: -20px;
    }
</style>
<div class="w100p bgl">
    <div class="w100p bgr p5b inner_container ">                        
        <div class="ctstcontainer">
            <div class="cttabs">
                <ul>
                    <li class="current">
                        <a title="Contest settings" href="admin.php?page=stFacebookToolbox&amp;action=dashboard" plugin_name="stContestToolbox"><span>Contest settings</span></a>
                    </li>
                    <li>
                        <a title="Contest fields" href="javascript:stContestToolbox.loadPage('contest_form', {contest_id: <?php if($result->contest_id) { echo $result->contest_id; } else { echo "0";}?>})" class="" plugin_name="stContestToolbox"><span>Contest fields</span></a>
                    </li>                    
                </ul>
            </div>              
        </div>
        <form class="stform" id="stFacebookToolboxForm" action="<?php echo admin_url('/admin.php?page=' . $config['plugin_name'] . '&action=' . $current_action) ?>" method="post" >
            <ul>   
                <li>
                    <fieldset style="border: 1px dotted;padding: 5px;">
                        <legend class="contest_legend"><?php _e('General Contest Settings', $config['plugin_name']); ?>:</legend>
                        <label><?php _e('Contest name', $config['plugin_name']); ?>:</label>                        
                        <div class="required">
                            <input value="<?php echo $result->name ?>" class="required" name="data[name]" id="name" type="text"/>
                        </div>
                        <br clear="both" />
                            
                        <label><?php _e('Start date', $config['plugin_name']); ?>:</label>
                        <div class="required">
                            <input value="<?php echo contest_format_date($result->start_date); ?>" class="required" name="data[start_date]" id="from" type="text"/>
                        </div>
                        <br clear="both" />
                            
                        <label><?php _e('End date', $config['plugin_name']); ?>:</label>
                        <div class="required">
                            <input value="<?php echo contest_format_date($result->end_date); ?>" class="required" name="data[end_date]" id="to" type="text"/>
                        </div>
                        <br clear="both" />                            
                        
                        <label><?php _e('Template name', $config['plugin_name']); ?>:</label>
                        <div>                            
                            <select name="data[template_name]">
                                <option value="default"<?php if($result->template_name == "default"){echo " selected='selected'";} ?>>Default</option>
                                <option value="bike"<?php if($result->template_name == "bike"){echo " selected='selected'";} ?>>Sport v1</option>
                                <option value="tierra"<?php if($result->template_name == "tierra"){echo " selected='selected'";} ?>>Tierra</option>
                                <option value="formbuilder"<?php if($result->template_name == "formbuilder"){echo " selected='selected'";} ?>>Form builder</option>
                            </select>
                        </div>
                        <br clear="both" />
                        
                        <label><?php _e('Banner overlay text', $config['plugin_name']); ?>:</label>
                        <div class="required">
                            <input value="<?php echo $result->overlay_text ?>" class="required" name="data[overlay_text]" id="overlay_text" type="text"/>
                        </div>
                        <br clear="both" />
                        
                        <label><?php _e('Banner overlay image', $config['plugin_name']); ?>:</label>
                        <div class="">
                              <?php
                            $class_hide = "hide";       
                            if($result->banner_overlay_image) {
                                $class_hide = "";
                            }
                            ?>
                                    <input type="hidden" id="id_upload_file" name="data[banner_overlay_image]" class="" value="<?php echo $result->banner_overlay_image;?>">
                                    <div class="upload_button_div">
                                        <span class="button image_upload_button" id="upload_file">Upload Image</span>
                                        <span class="button image_reset_button <?php echo $class_hide ?>" id="reset_upload_file" pictureid="upload_file">Remove</span>


                                    </div>  
                                     <?php                                       
                                    if($result->banner_overlay_image) {
                                        ?>
                                    <img class="preview" id="image_upload_file" src="<?php echo $result->banner_overlay_image;?>" alt="" />
                                    <?php 
                                    }
                                    ?>


                        </div>
                        <br clear="both" />
                        
                    </fieldset>
                    <br clear="both" />
                </li>  
                
                <!--
                <li>
                    <label><?php _e('Title', $config['plugin_name']); ?>:</label>
                    <div class="required">
                        <input value="<?php echo $result->title ?>" class="required" name="data[title]" id="title" type="text"/>
                    </div>
                    <br clear="both" />
                </li>  
                -->                                
                
                <li>                    
                    <fieldset style="border: 1px dotted;padding: 5px;">
                        <legend class="contest_legend"><?php _e('About Contest Tab', $config['plugin_name']); ?>:</legend>
                    
                       
                    <label><?php _e('Show tab', $config['plugin_name']); ?>:</label>
                    <div>
                        <!-- <input value="<?php echo $result->show_about_tab; ?>" class="" name="data[show_about_tab]" id="tab_lable" type="text"/> -->
                        <input type="checkbox" name="data[show_about_tab]"<?php if($result->show_about_tab == "on" || $result->show_about_tab == "") {?> checked="checked" <?php } ?> />
                    </div>
                    <br clear="both" />
                    
                    <label><?php _e('Tab Label', $config['plugin_name']); ?>:</label>
                    <div class="required">
                        <input value="<?php echo $result->tab_lable; ?>" class="required" name="data[tab_lable]" id="tab_lable" type="text"/>
                    </div>
                    <br clear="both" />
                    <?php
                    $functions->customEditor(stripslashes($result->description),'description');
                    ?>
                    <!-- resize field -->
                    <script type="text/javascript">
                        function resizefordescriptionEditor(){
                            var f = document.getElementById("data[description]_ifr");
                            if(f == null) {
                                setTimeout("resizefordescriptionEditor()", 1000);
                            } else {
                                f.style.height = "350px";
                            }                            
                        }
                        resizefordescriptionEditor();                        
                        
                    </script>
                    </fieldset>
                    <br clear="both" />
                </li> 
                
                <li>
                    <fieldset style="border: 1px dotted;padding: 5px;">
                        <legend class="contest_legend"><?php _e('Contest Terms of Service', $config['plugin_name']); ?>:</legend>
                        
                    <label><?php _e('Contest TOS link text', $config['plugin_name']); ?>:</label>
                    <div class="required">
                        <input value="<?php echo $result->tos_link_text; ?>" class="required" name="data[tos_link_text]" id="tos_link_text" type="text"/>
                    </div>
                    <br clear="both" />                                        
                    
                    <?php
                    $functions->customEditor(stripslashes($result->tos_text),'tos_text');
                    ?>
                    <!-- resize field -->
                    <script type="text/javascript">
                        function resizefortos_textEditor(){
                            var f = document.getElementById("data[tos_text]_ifr");
                            if(f == null) {
                                setTimeout("resizefortos_textEditor()", 1000);
                            } else {
                                f.style.height = "350px";
                            }                            
                        }
                        resizefortos_textEditor();                        
                        
                    </script>
                    </fieldset>
                    <br clear="both" />                    
                </li>
                
                <li>
                    <fieldset style="border: 1px dotted;padding: 5px;">
                        <legend class="contest_legend"><?php _e('External link tab', $config['plugin_name']); ?>:</legend>
                        
                        <label><?php _e('Show tab', $config['plugin_name']); ?>:</label>
                        <div>
                            <!-- <input value="<?php echo $result->show_about_tab; ?>" class="" name="data[show_about_tab]" id="tab_lable" type="text"/> -->
                            <input type="checkbox" name="data[show_external_tab]"<?php if($result->show_external_tab == "on" || $result->show_external_tab == "") {?> checked="checked" <?php } ?> />
                        </div>
                        <br clear="both" />
                        
                        <label><?php _e('Tab Label', $config['plugin_name']); ?>:</label>
                        <div class="required">
                            <input value="<?php echo $result->external_tab_text; ?>" class="required" name="data[external_tab_text]" id="external_tab_text" type="text"/>
                        </div>
                        <br clear="both" /> 
                        
                        <label><?php _e('Tab URL', $config['plugin_name']); ?>:</label>
                        <div class="required">
                            <input value="<?php echo $result->external_tab_url; ?>" class="required" name="data[external_tab_url]" id="external_tab_text" type="text"/>
                        </div>
                        <br clear="both" />
                        
                    </fieldset>
                    <br clear="both" />                    
                </li>
                
                <li>
                    <fieldset style="border: 1px dotted;padding: 5px;">
                        <legend class="contest_legend"><?php _e('Sign-up settings', $config['plugin_name']); ?>:</legend>
                        
                        <label><?php _e('Show tab', $config['plugin_name']); ?>:</label>
                        <div>
                            <!-- <input value="<?php echo $result->show_about_tab; ?>" class="" name="data[show_about_tab]" id="tab_lable" type="text"/> -->
                            <input type="checkbox" name="data[show_signup_tab]"<?php if($result->show_signup_tab == "on" || $result->show_signup_tab == "") {?> checked="checked" <?php } ?> />
                        </div>
                        <br clear="both" />
                        
                        <label><?php _e('Tab label', $config['plugin_name']); ?>:</label>
                        <div class="required">
                            <input value="<?php echo $result->signup_tab_lable; ?>" class="required" name="data[signup_tab_lable]" id="signup_tab_lable" type="text"/>
                        </div>
                        <br clear="both" /> 
                        
                        <?php
                        $functions->customEditor(stripslashes($result->signup_tab_text),'signup_tab_text');
                        ?>
                        <!-- resize field -->
                        <script type="text/javascript">
                            function resizeforsignup_tab_textEditor(){
                                var f = document.getElementById("data[signup_tab_text]_ifr");
                                if(f == null) {
                                    setTimeout("resizeforsignup_tab_textEditor()", 1000);
                                } else {
                                    f.style.height = "300px";
                                }                            
                            }
                            resizeforsignup_tab_textEditor();                        

                        </script>
                        
                    </fieldset>
                    <br clear="both" />                    
                </li>
                
                <li>
                    <fieldset style="border: 1px dotted;padding: 5px;">
                        <legend class="contest_legend"><?php _e('Contribution tab', $config['plugin_name']); ?>:</legend>                        
                        <label><?php _e('Show tab', $config['plugin_name']); ?>:</label>
                        <div>                           
                            <input type="checkbox" name="data[show_contribution_tab]"<?php if($result->show_contribution_tab == "on" || $result->show_contribution_tab == "") {?> checked="checked" <?php } ?> />
                        </div>
                        <br clear="both" />                        
                        <label><?php _e('Tab label', $config['plugin_name']); ?>:</label>
                        <div class="required">
                            <input value="<?php echo $result->contribution_tab_label; ?>" class="required" name="data[contribution_tab_label]" id="contribution_tab_label" type="text"/>
                        </div>
                        <br clear="both" />                                                 
                    </fieldset>
                    <br clear="both" />                    
                </li>
                
                <li>
                    <fieldset style="border: 1px dotted;padding: 5px;">
                        <legend class="contest_legend"><?php _e('Facebook auto post settings', $config['plugin_name']); ?>:</legend>
                        
                        <label><?php _e('Auto post to users wall', $config['plugin_name']); ?>:</label>
                        <div>                            
                            <input type="checkbox" name="data[autopost_is_active]"<?php if($result->autopost_is_active == "on" || $result->autopost_is_active == "") {?> checked="checked" <?php } ?> />
                        </div>
                        <br clear="both" />
                        
                        <label><?php _e('Wall post title', $config['plugin_name']); ?>:</label>
                        <div class="required">
                            <input value="<?php echo $result->autopost_title; ?>" class="required" name="data[autopost_title]" id="autopost_title" type="text"/>
                        </div>
                        <br clear="both" /> 
                        
                        <label><?php _e('Wall post text', $config['plugin_name']); ?>:</label>
                        <div class="required">
                            <textarea class="required" name="data[autopost_text]" id="autopost_text"><?php echo $result->autopost_text; ?></textarea>
                        </div>
                        <br clear="both" />  
                        
                        <label><?php _e('Wall post image/logo', $config['plugin_name']); ?>:</label>
                        <div class="">
                              <?php
                            $class_hide = "hide";       
                            if($result->autopost_image) {
                                $class_hide = "";
                            }
                            ?>
                                    <input type="hidden" id="id_autopost_image" name="data[autopost_image]" class="" value="<?php echo $result->autopost_image;?>">
                                    <div class="upload_button_div">
                                        <span class="button image_upload_button" id="upload_file_autopost_image">Upload Image</span>
                                        <span class="button image_reset_button <?php echo $class_hide ?>" id="reset_upload_file" pictureid="upload_file_autopost_image">Remove</span>


                                    </div>  
                                     <?php                                       
                                    if($result->autopost_image) {
                                        ?>
                                    <img class="preview" id="image_upload_file_autopost_image" src="<?php echo $result->autopost_image;?>" alt="" />
                                    <?php 
                                    }
                                    ?>


                        </div>
                        <br clear="both" />
                        
                    </fieldset>
                    <br clear="both" />                    
                </li>
                
                <li>
                    <fieldset style="border: 1px dotted;padding: 5px;">
                        <legend class="contest_legend"><?php _e('Post on friends wall settings', $config['plugin_name']); ?>:</legend>
                        
                        <label><?php _e('Post on friends wall', $config['plugin_name']); ?>:</label>
                        <div>                            
                            <input type="checkbox" name="data[friendpost_is_active]"<?php if($result->friendpost_is_active == "on" || $result->friendpost_is_active == "") {?> checked="checked" <?php } ?> />
                        </div>
                        <br clear="both" />
                        
                        <label><?php _e('Wall post title', $config['plugin_name']); ?>:</label>
                        <div class="required">
                            <input value="<?php echo $result->friendpost_title; ?>" class="required" name="data[friendpost_title]" id="friendpost_title" type="text"/>
                        </div>
                        <br clear="both" /> 
                        
                        <label><?php _e('Wall post text', $config['plugin_name']); ?>:</label>
                        <div class="required">
                            <textarea class="required" name="data[friendpost_text]" id="friendpost_text"><?php echo $result->friendpost_text; ?></textarea>
                        </div>
                        <br clear="both" />  
                        
                        <label><?php _e('Wall post image/logo', $config['plugin_name']); ?>:</label>
                        <div class="">
                              <?php
                            $class_hide = "hide";       
                            if($result->friendpost_image) {
                                $class_hide = "";
                            }
                            ?>
                                    <input type="hidden" id="id_friendpost_image" name="data[friendpost_image]" class="" value="<?php echo $result->friendpost_image;?>">
                                    <div class="upload_button_div">
                                        <span class="button image_upload_button" id="upload_file_friendpost_image">Upload Image</span>
                                        <span class="button image_reset_button <?php echo $class_hide ?>" id="reset_upload_file" pictureid="upload_file_friendpost_image">Remove</span>


                                    </div>  
                                     <?php                                       
                                    if($result->friendpost_image) {
                                        ?>
                                    <img class="preview" id="image_upload_file_friendpost_image" src="<?php echo $result->autopost_image;?>" alt="" />
                                    <?php 
                                    }
                                    ?>


                        </div>
                        <br clear="both" />
                        
                    </fieldset>
                    <br clear="both" />                    
                </li>
                
                
                
                <li>
                    <fieldset style="border: 1px dotted;padding: 5px;">
                        <legend class="contest_legend"><?php _e('Share/like text settings', $config['plugin_name']); ?>:</legend>
                        
                        <label><?php _e('Share title', $config['plugin_name']); ?>:</label>
                        <div>                            
                            <input value="<?php echo $result->share_title; ?>" class="required" name="data[share_title]" id="share_title" type="text"/>
                        </div>
                        <br clear="both" />
                        
                        <label><?php _e('Share text', $config['plugin_name']); ?>:</label>
                        <div class="required">                            
                            <textarea class="required" name="data[share_text]" id="share_text"><?php echo $result->share_text; ?></textarea>
                        </div>
                        <br clear="both" />  
                        
                        <label><?php _e('Share action link text', $config['plugin_name']); ?>:</label>
                        <div class="required">                                                       
                            <input value="<?php echo $result->share_action_text; ?>" class="required" name="data[share_action_text]" id="share_action_text" type="text"/>
                        </div>
                        <br clear="both" />                                                
                        
                        <label><?php _e('Share image', $config['plugin_name']); ?>:</label>
                        <div class="">
                              <?php
                            $class_hide = "hide";       
                            if($result->share_image) {
                                $class_hide = "";
                            }
                            ?>
                                    <input type="hidden" id="id_share_image" name="data[share_image]" class="" value="<?php echo $result->share_image;?>">
                                    <div class="upload_button_div">
                                        <span class="button image_upload_button" id="upload_file_share_image">Upload Image</span>
                                        <span class="button image_reset_button <?php echo $class_hide ?>" id="reset_upload_file" pictureid="upload_file_share_image">Remove</span>


                                    </div>  
                                     <?php                                       
                                    if($result->share_image) {
                                        ?>
                                    <img class="preview" id="image_upload_file_share_image" src="<?php echo $result->share_image;?>" alt="" />
                                    <?php 
                                    }
                                    ?>


                        </div>
                        <br clear="both" />
                        
                    </fieldset>
                    <br clear="both" />                    
                </li>
                                
                <li>
                    <fieldset style="border: 1px dotted;padding: 5px;">
                        <legend class="contest_legend"><?php _e('Like trap settings', $config['plugin_name']); ?>:</legend>
                        
                        <label><?php _e('Use like trap for this contest', $config['plugin_name']); ?>:</label>
                        <div>                            
                            <input type="checkbox" name="data[like_trap_is_active]"<?php if($result->like_trap_is_active == "on" || $result->like_trap_is_active == "") {?> checked="checked" <?php } ?> />
                        </div>
                        <br clear="both" />                        
                        <label><?php _e('Content to show for non-likes', $config['plugin_name']); ?>:</label>
                        <br clear="both" />
                        <?php
                        $functions->customEditor(stripslashes($result->like_trap_content),'like_trap_content');
                        ?>
                        <!-- resize field -->
                        <script type="text/javascript">
                            function resizeforlike_trap_contentEditor(){
                                var f = document.getElementById("data[like_trap_content]_ifr");
                                if(f == null) {
                                    setTimeout("resizeforlike_trap_contentEditor()", 1000);
                                } else {
                                    f.style.height = "300px";
                                }                            
                            }
                            resizeforlike_trap_contentEditor();                        

                        </script>
                        
                    </fieldset>
                    <br clear="both" />                    
                </li>
               
                <li>
                    <input type="submit" value="Save"/>
                </li>
            </ul>
            <input type="hidden" value="<?php echo $result->contest_id ?>" id="id" name="data[contest_id]"/>
        </form>
    </div>
</div>
<script type="text/javascript" >   
    jQuery('#from').datetimepicker({"dateFormat":"dd.mm.yy"});
    jQuery('#to').datetimepicker({"dateFormat":"dd.mm.yy"});
</script>
